let best = window.localStorage.getItem('2048bestScore')||0;
function showNumberWithAnimation(i, j, ranNumber){
    let numberCell = $(`#number-cell-${i}-${j}`)
    numberCell.css("background-color", getNumberBackgroundColor(board[i][j]))
    numberCell.css("color", getNumberColor(board[i][j]))
    numberCell.text(ranNumber)
    numberCell.animate({   
        width:cellLength,
        height:cellLength,
        top:getPosTop(i,j),
        left:getPosLeft(i,j)
    },50)
}


function showMoveAnimation(fromX, fromY, toX, toY) {
    let tarCell = $(`#number-cell-${fromX}-${fromY}`)
    tarCell.animate({
        top: getPosTop(toX,toY),
        left: getPosLeft(toX,toY)
    }, 200)
}

function updataScoreAnimation(num){
    $('#score').text(num)
    if(num>best){
        $('#best').text(num)
    }
}


// 显示模态框
function showModal() {
    $("#cover").css("display", "block");
    $("#cover").animate({
        width: "100%",
        height: "100%",
        top: "0",
        left: "0"
    }, 500);
    $("#cover-content").animate({
        width: 0.75 * domWidth,
        height: 0.75 * domWidth * 0.7,
        marginLeft: -(0.75 * domWidth * 0.5),
        marginTop: -(0.75 * domWidth * 0.7 * 0.5),
    }, 100);

    $('#cover-content').click(()=>{
        closeModal()
    })
}

// 关闭模态框
function closeModal() {
    $("#cover").removeAttr("style");
    $("#cover-content").removeAttr("style");
}